home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 120 / CD Gamer Issue 120 (March 2003) (Disc 2).ISO / mods / Q2_Codered / codeRED1_0.exe / Data1.cab / NPC_droid.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-20  |  7.1 KB  |  298 lines

  1. /*
  2. ==============================================================================
  3.  
  4. Droid NPC
  5.  
  6. ==============================================================================
  7. */
  8.  
  9. #include "g_local.h"
  10. #include "npc_droid.h"
  11.  
  12.  
  13. static int sound_pain;
  14. static int sound_walk;
  15. static int sound_idle;
  16. static int sound_talk;
  17. static int sound_talk2;
  18. static int sound_sight;
  19. static int sound_search;
  20. static int sound_spark;
  21.  
  22. void droid_standstill (edict_t *self);
  23. void droid_fidget (edict_t *self);
  24. void droid_damaged (edict_t *self);
  25.  
  26. void droid_search (edict_t *self)
  27. {
  28.     gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
  29. }
  30.  
  31. mframe_t droid_frames_stand [] =
  32. {
  33.     ai_stand, 0, droid_fidget
  34. };
  35. mmove_t droid_move_stand = {FRAME_stand01, FRAME_stand01, droid_frames_stand, NULL};
  36.  
  37. void droid_stand (edict_t *self)
  38. {
  39.     gi.sound (self, CHAN_VOICE, sound_idle, 1, ATTN_IDLE, 0);
  40.     self->monsterinfo.currentmove = &droid_move_stand;
  41. }
  42.  
  43. mframe_t droid_frames_fidget [] =
  44. {
  45.     ai_stand, 0, NULL,
  46.     ai_stand, 0, NULL,
  47.     ai_stand, 0, NULL,
  48.     ai_stand, 0, NULL,
  49.     ai_stand, 0, NULL,
  50.     ai_stand, 0, NULL,    
  51.     ai_stand, 0, NULL,
  52.     ai_stand, 0, NULL,
  53.     ai_stand, 0, NULL,
  54.     ai_stand, 0, NULL,
  55.     ai_stand, 0, NULL,
  56.     ai_stand, 0, NULL,
  57.     ai_stand, 0, NULL,
  58.     ai_stand, 0, NULL,
  59.     ai_stand, 0, NULL,
  60.     ai_stand, 0, NULL,
  61.     ai_stand, 0, NULL,    
  62.     ai_stand, 0, NULL,
  63.     ai_stand, 0, NULL,
  64.     ai_stand, 0, NULL,
  65.     ai_stand, 0, NULL
  66.     
  67. };
  68. mmove_t droid_move_fidget = {FRAME_comm01, FRAME_comm20, droid_frames_fidget, droid_stand};
  69.  
  70. void droid_fidget (edict_t *self)
  71. {
  72.     if (self->spawnflags & 8) // don't want him to be at a console.
  73.         return;
  74.     if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  75.         return;
  76.     if (random() > 0.25)
  77.         return;
  78.  
  79.     self->monsterinfo.currentmove = &droid_move_fidget;
  80.     gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_IDLE, 0);
  81. }
  82.  
  83. mframe_t droid_frames_still [] =
  84. {
  85.  
  86.     ai_still, 0, NULL
  87.     
  88. };
  89. mmove_t droid_move_standstill = {FRAME_stand01, FRAME_stand01, droid_frames_still, droid_standstill};
  90.  
  91. void droid_standstill (edict_t *self)
  92. {
  93.     self->monsterinfo.currentmove = &droid_move_standstill;
  94. }
  95. void droid_step (edict_t *self)
  96. {
  97.     gi.sound (self, CHAN_VOICE, sound_walk, 1, ATTN_NORM, 0);
  98. }
  99. mframe_t droid_frames_walk [] =
  100. {
  101.     ai_run, 1.0, droid_step,
  102.     ai_run, 3.3, NULL,
  103.     ai_run, 8.9, NULL,
  104.     ai_run, 10.0, NULL,
  105.     ai_run, 0.0, NULL,
  106.     ai_run, 0.0, NULL,
  107.     ai_run, 1.0, droid_step,
  108.     ai_run, 3.0, NULL,
  109.     ai_run, 8.0, NULL,
  110.     ai_run, 10.0, NULL,
  111.     ai_run, 0.0, NULL,
  112.     ai_run, 0.0, NULL,
  113. };
  114. mmove_t droid_move_walk = {FRAME_walk01, FRAME_walk12, droid_frames_walk, NULL};
  115.  
  116. void droid_walk (edict_t *self)
  117. {
  118.     if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  119.         self->monsterinfo.currentmove = &droid_move_stand;
  120.     else
  121.         self->monsterinfo.currentmove = &droid_move_walk;
  122. }
  123.  
  124. void droid_run_after_talk (edict_t *self)
  125. {
  126.     self->monsterinfo.currentmove = &droid_move_walk;
  127. }
  128.  
  129.  
  130. void droidTalk (edict_t *self)
  131. {
  132.     if (self->spawnflags & 1)
  133.         gi.sound(self, CHAN_VOICE, sound_talk2, 1, ATTN_IDLE, 0);
  134.     else
  135.         gi.sound (self, CHAN_VOICE, sound_talk, 1, ATTN_IDLE, 0);
  136. }
  137.  
  138. mframe_t droid_frames_talk [] =
  139. {
  140.     ai_charge, 0, droidTalk
  141. };
  142. mmove_t droid_move_talk = {FRAME_stand01, FRAME_stand01, droid_frames_talk, droid_standstill};
  143.  
  144. void droid_sight (edict_t *self, edict_t *other)
  145. {
  146.     gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  147.     self->monsterinfo.currentmove = &droid_move_walk;
  148. }
  149.  
  150. void droid_melee (edict_t *self)
  151. {
  152.     self->monsterinfo.currentmove = &droid_move_talk;
  153. }
  154.  
  155. void droid_dead (edict_t *self)
  156. {
  157.     VectorSet (self->mins, -16, -16, 0);
  158.     VectorSet (self->maxs, 16, 16, 24);
  159.     self->movetype = MOVETYPE_TOSS;
  160.     self->svflags |= SVF_DEADMONSTER;
  161.     self->nextthink = 0;
  162.     gi.linkentity (self);
  163. }
  164.  
  165. void droid_spark(edict_t *self)
  166. {
  167.     gi.sound (self, CHAN_VOICE, sound_spark, 1, ATTN_NORM, 0);
  168. }
  169.  
  170. mframe_t droid_frames_damaged [] =
  171. {
  172.     ai_move, 0, droid_spark,
  173.     ai_move, 0, NULL,
  174.     ai_move, 0, NULL,
  175.     ai_move, 0, droid_spark,
  176.     ai_move, 0, NULL,
  177.     ai_move, 0, NULL
  178.     
  179. };
  180. mmove_t droid_move_damaged = {FRAME_dama01, FRAME_dama06, droid_frames_damaged, droid_damaged};
  181.  
  182. void droid_damaged (edict_t *self)
  183. {
  184.     self->monsterinfo.aiflags = AI_RESURRECTING;
  185.     M_SetEffects (self);
  186.  
  187.     self->monsterinfo.currentmove = &droid_move_damaged;
  188. }
  189.  
  190. void droid_pain (edict_t *self, edict_t *other, float kick, int damage)
  191. {
  192.     if (level.time < self->pain_debounce_time)
  193.         return;
  194.  
  195.     self->pain_debounce_time = level.time + 3;
  196.     gi.sound (self, CHAN_VOICE, sound_pain, 1, ATTN_IDLE, 0);
  197.  
  198.     self->monsterinfo.aiflags = AI_RESURRECTING;
  199.     M_SetEffects(self);
  200.  
  201.     self->monsterinfo.currentmove = &droid_move_damaged;
  202. }
  203.  
  204. void droid_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  205. {
  206.     if (self->health <= self->gib_health)
  207.     {
  208.         gi.WriteByte (svc_temp_entity);
  209.         gi.WriteByte (TE_EXPLOSION1);
  210.         gi.WritePosition (self->s.origin);
  211.         gi.multicast (self->s.origin, MULTICAST_PVS);
  212.         self->deadflag = DEAD_DEAD;
  213.         G_FreeEdict (self);
  214.         return;
  215.     }
  216.  
  217.     if (self->deadflag == DEAD_DEAD)
  218.         return;
  219.  
  220.     self->takedamage = DAMAGE_YES;
  221.  
  222.     self->monsterinfo.currentmove = &droid_move_damaged;
  223. }
  224.  
  225.  
  226. /*QUAKED monster_droid (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
  227. */
  228. void SP_npc_droid (edict_t *self)
  229. {
  230.     if (deathmatch->value)
  231.     {
  232.         G_FreeEdict (self);
  233.         return;
  234.     }
  235.     
  236.     // pre-caches
  237.     sound_pain  = gi.soundindex ("droid/pain.wav");
  238.     sound_idle  = gi.soundindex ("droid/idle.wav");
  239.     sound_talk = gi.soundindex ("droid/talk.wav");
  240.     sound_talk2 = gi.soundindex ("droid/talk2.wav");
  241.     sound_search = gi.soundindex ("droid/idle.wav");
  242.     sound_sight = gi.soundindex ("droid/comm.wav");
  243.     sound_spark = gi.soundindex ("droid/spark.wav");
  244.     sound_walk = gi.soundindex ("droid/walk.wav");
  245.  
  246.     self->s.modelindex = gi.modelindex("models/npc/droid/tris.md2");
  247.  
  248.     VectorSet (self->mins, -16, -16, 0);
  249.     VectorSet (self->maxs, 16, 16, 56);
  250.     self->movetype = MOVETYPE_STEP;
  251.     self->solid = SOLID_BBOX;
  252.  
  253.     self->classname = "npc_droid";
  254.       
  255.     self->max_health = 100;
  256.     self->health = self->max_health;
  257.     self->gib_health = 40;
  258.     self->mass = 50;
  259.  
  260.     if (self->spawnflags & 16)
  261.     {
  262.         self->pain = droid_pain;        
  263.         self->die = droid_die;
  264.         self->monsterinfo.stand = droid_damaged;
  265.         self->monsterinfo.walk = droid_damaged;
  266.         self->monsterinfo.run = droid_damaged;
  267.         self->monsterinfo.dodge = NULL;
  268.         self->monsterinfo.attack = NULL;
  269.         self->monsterinfo.melee = droid_damaged;
  270.         self->monsterinfo.sight = NULL;
  271.         self->monsterinfo.search = droid_damaged;
  272.  
  273.         self->monsterinfo.currentmove = &droid_move_damaged;
  274.         self->monsterinfo.aiflags = AI_RESURRECTING;
  275.     }
  276.     else
  277.     {
  278.         self->pain = droid_pain;        
  279.         self->die = droid_die;
  280.         self->monsterinfo.stand = droid_stand;
  281.         self->monsterinfo.walk = droid_walk;
  282.         self->monsterinfo.run = droid_walk;
  283.         self->monsterinfo.dodge = NULL;
  284.         self->monsterinfo.attack = NULL;
  285.         self->monsterinfo.melee = droid_melee;
  286.         self->monsterinfo.sight = droid_sight;
  287.         self->monsterinfo.search = droid_search;
  288.  
  289.         self->monsterinfo.currentmove = &droid_move_stand;
  290.     }
  291.     
  292.     self->monsterinfo.scale = MODEL_SCALE;
  293.  
  294.     gi.linkentity (self);
  295.  
  296.     walkmonster_start (self);
  297. }
  298.